<template>
    <div class="page_box_mod">
        <!--局部页面背景-->
        <div class="loginBack_mod" v-loading="loading">
            <div class="backMask_mod">
            </div>
            <!--登录框-->
            <div class="nav_mod">
                <a href="../home.html">
                    <img src="../assets/photos/logo/AUT.png" />
                </a>
            </div>

            <div class="login_form_mod">
                <label class="account_text">账号</label>
                <input class="account_mod" type="text" v-model="userForm.admin_Email" />
                <label class="password_text">密码</label>
                <input class="password_mod" type="password" v-model="userForm.admin_Password" />

                <label class="remPassword_text">记住密码</label>

                <input class="rememberPassword_mod" type="checkbox" v-model="userForm.remFlag" />
                <button class="signIn_mod" @click="submitForm">登录
                </button>
                <router-link to="/SignUp" class="signUp_mod">没有账号?</router-link>
            </div>
        </div>
    </div>
</template>
<style scoped src="../style/login.css"></style>
<script>
import router from '@/router';
export default {
    data() {
        return {
            loading: false,
            userForm: {
                admin_Email: '',
                admin_Password: '',
                remFlag: false,
            }
        }
    },
    mounted() {
        //this.getCookie();
    },

    methods: {
        /*获取cookie的数据*/
        getCookie() {
            let that = this;
            this.$axios({
                method: 'GET',
                url: 'http://localhost:8080/user/cookie'
            }).then(resp => {
                that.userForm = resp.data.data
                that.userForm.remFlag = true;
            })
        },

        /*登录提交*/
        submitForm() {
            let that = this;
            this.$axios({
                method: 'POST',
                url: 'http://localhost:8080/admin/adminLogin',
                data: this.userForm,
            }).then(resp => {
                that.loading = false
                if (resp.data.flag) {
                    router.push("/")
                    console.log(resp.data.data)
                    window.sessionStorage.setItem('admin_ID', resp.data.data);
                } else {
                    if (resp.data.code === 402) {
                        this.$notify({
                            title: '提示信息',
                            message: resp.data.data,
                            type: 'error'
                        })
                    }
                    if (resp.data.code === 200) {
                        $(".signIn_mod").html("登录")
                        this.$confirm(resp.data.msg, '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning',
                            center: true
                        }).then(() => {
                            that.userForm.user_email = ""
                            that.userForm.user_password = ""
                        })
                    }
                }
            })

        }
    }
}
</script>